//
//  OldViewController.m
//  SHShopping
//
//  Created by 坤鼎 on 2019/9/1.
//  Copyright © 2019 kunding. All rights reserved.
//

#import "OldViewController.h"
#import "OldTableViewCell.h"
#import "DiscoverTableViewCell.h"
#import "PublicRightImageCell.h"
#import "PublicThreeImageCell.h"
#import "FiveBtnView.h"
#import <SDCycleScrollView.h>
#import "VideoDetailViewController.h"
#import "MPMoviePlayerVC.h"
#import "ListNightSHTweetModel.h"
#import "FiveBtnMoreViewController.h"
#import "OldDetailViewController.h"
#import "OldActivityModel.h"

@interface OldViewController () <UITableViewDelegate, UITableViewDataSource, SDCycleScrollViewDelegate>

@property (nonatomic, strong) UIView *tabHeaderView;//老字号头视图
@property (nonatomic, strong) SDCycleScrollView *sdcycleScrollView;//体验头视图
@property (nonatomic, strong) UIButton *btnTop0;//老字号
@property (nonatomic, strong) UIButton *btnTop1;//体验
@property (nonatomic, strong) UIButton *btnTop2;//商城

@property (nonatomic, strong) FiveBtnView *fiveBtn;

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIImageView *image3;

@property (nonatomic, strong) NSDictionary *dataDic;
@property (nonatomic, strong) NSMutableArray *tableViewDataArr;
@property (nonatomic, strong) NSMutableArray *listNightSHTweetModelArr;
@property (nonatomic, strong) NSMutableArray *lzh_listLZHStorylArr;//老故事视频


@property (nonatomic, assign) NSInteger refreshCount;//上滑次数
@property (nonatomic, assign) NSInteger totalCount;//列表个数


@property (nonatomic, copy) NSString *topNavId;//当前选中的Nav ID
@property (nonatomic, assign) NSInteger navSelectedIndex;//当前选中的Nav index
@property (nonatomic, assign) NSInteger navLastSelectedIndex;//上一次选中的Nav index
@property (nonatomic, strong) UILabel *lbTitle;//商城抬头

@property (nonatomic, strong) ListNightSHTweetModel *shareDataModel;


@end

@implementation OldViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navSelectedIndex = 0;
    //布局UI
    [self createUI];
    [self.view addSubview:self.tableView];
    [self addNav];
    
    
    // 添加头部的下拉刷新
    MJRefreshNormalHeader *header = [[MJRefreshNormalHeader alloc] init];
    [header setRefreshingTarget:self refreshingAction:@selector(headerClick)];
    self.tableView.mj_header = header;
    [self.tableView.mj_header beginRefreshing];
    
    // 添加底部的上拉加载
    MJRefreshBackNormalFooter *footer = [[MJRefreshBackNormalFooter alloc] init];
    [footer setRefreshingTarget:self refreshingAction:@selector(footerClick)];
    self.tableView.mj_footer = footer;
    
    self.tableView.rowHeight = UITableViewAutomaticDimension; // 自适应xib高度
    self.tableView.estimatedRowHeight = 100; //先估计一个高度
    
    self.tableView.backgroundColor = [UIColor whiteColor];
}

// 头部的下拉刷新触发事件
- (void)headerClick {
    
    self.refreshCount = 1;
    [self loadData];
    // 结束刷新
    [self.tableView.mj_header endRefreshing];
}
// 底部的上拉加载触发事件
- (void)footerClick {
    
    if (self.navSelectedIndex == 1) {
        self.refreshCount++;
        [self addData];
    }
}

- (void)loadData {
    [SXLoadingView showProgressHUD:nil];
    
    if (self.listNightSHTweetModelArr.count != 0) {
        [self.listNightSHTweetModelArr removeAllObjects];
    }
    
    [PPNetworkHelper POST:URL_lzhInit parameters:nil success:^(id responseObject) {
        [SXLoadingView hideProgressHUD];
        self.dataDic = responseObject[@"retBody"];
        
        
        [self setData];
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [SXLoadingView showAlertHUD:SXLoadingErrorStr duration:SXLoadingErrorTime];
    }];
}

- (void)setData {
    self.tableViewDataArr = [OldActivityModel arrayOfModelsFromDictionaries:self.dataDic[@"lzh_listLZHActivity"] error:nil];
    [self.fiveBtn updateFiveBtnViewWith:self.dataDic[@"lzh_listLZHImg"]];
    self.fiveBtn.lbTitle.text = [NSString stringWithFormat:@"%@", self.dataDic[@"lzh_listLZHTopNav"][0][@"title"]];
    self.fiveBtn.lbDetailTitle.text = [NSString stringWithFormat:@"%@", self.dataDic[@"lzh_listLZHTopNav"][0][@"presentation"]];
    [self.image3 sd_setImageWithURL:[NSURL URLWithString:self.dataDic[@"lzh_listLZHTopNav"][0][@"imgPath"]] placeholderImage:LHYPlaceholderImage];
    self.listNightSHTweetModelArr = [ListNightSHTweetModel arrayOfModelsFromDictionaries:self.dataDic[@"ty_listLZHTweet"] error:nil];
    self.lzh_listLZHStorylArr = [ListNightSHTweetModel arrayOfModelsFromDictionaries:self.dataDic[@"lzh_listLZHStory"] error:nil];
}
//注意:  老字号活动没有上拉加载,    体验有上拉加载
- (void)addData {
    NSDictionary *par = @{@"page":@(self.refreshCount),
                          @"pageSize":@"5"
                          };
    [PPNetworkHelper POST:URL_lzhNext parameters:par success:^(id responseObject) {
        NSArray *arr = responseObject[@"retBody"][@"rows"];
        self.totalCount = [responseObject[@"retBody"][@"total"] integerValue];
        
        if (IsNotNilArr(arr)) {
            NSArray *modleArr = [ListNightSHTweetModel arrayOfModelsFromDictionaries:arr error:nil];
            [self.listNightSHTweetModelArr addObjectsFromArray:modleArr];
        }
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [SXLoadingView showAlertHUD:SXLoadingErrorStr duration:SXLoadingTime];
    }];
}

- (void)createUI {
    _tabHeaderView = [[UIView alloc] init];
    //圆角图
    self.image3 = [[UIImageView alloc] initWithFrame:CGRectMake(ADAPT_W(16), 0, SCREEN_WIDTH - ADAPT_W(32), ADAPT_W(180))];
    self.image3.backgroundColor = [UIColor whiteColor];
    self.image3.layer.cornerRadius = 10;//圆角
    self.image3.layer.masksToBounds = YES;
    
    [self.tabHeaderView addSubview:self.image3];
#pragma mark - 夜上海专线
    self.fiveBtn = [[FiveBtnView alloc] initWithFrame:CGRectMake(0, GetViewYH(self.image3) + 18, SCREEN_WIDTH, SCREEN_WIDTH * 344.f/375.f)];
    
    WeakSelf;
    self.fiveBtn.clickRedeemBlock = ^(UIButton * _Nonnull sender) {
        StrongSelf;
        if ([sender.titleLabel.text isEqualToString:@"更多"]) {
            FiveBtnMoreViewController *vc = [[FiveBtnMoreViewController alloc] init];
            vc.title = @"老字号专线";
            [strongSelf.navigationController pushViewController:vc animated:YES];
        } else {
            NSDictionary *dic = strongSelf.dataDic[@"lzh_listLZHImg"][sender.tag - 40];
            if ([WXApi isWXAppInstalled]) {
                WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
                launchMiniProgramReq.userName = dic[@"appId"];  //拉起的小程序的username-原始ID
                launchMiniProgramReq.path = dic[@"appPath"];    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
                launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
                [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                    
                }];
            } else {
                [SXLoadingView showAlertHUD:@"您还未安装微信~请先下载安装哦" duration:SXLoadingTime];
            }
        }
    };
    [self.tabHeaderView addSubview:self.fiveBtn];
    
    UILabel *lbTitle = [[UILabel alloc] initWithFrame:CGRectMake(16, GetViewYH(self.fiveBtn) + 10, SCREEN_WIDTH - 32, 31)];
    lbTitle.text = @"老字号故事";
    lbTitle.font = FONT_BOLD(22);
    [_tabHeaderView addSubview:lbTitle];
    
    self.tabHeaderView.frame = CGRectMake(0, 0, SCREEN_WIDTH, GetViewYH(lbTitle) + 15);
}

- (void)addNav {
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight - ADAPT_W(30), 40, 34)];
    [btn setImage:ImageNamed(@"enter") forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
 
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH - 300)/2, kNavBarAndStatusBarHeight - ADAPT_W(30), 300, 34)];
    [self.view addSubview:view];
    NSArray *arr = @[@"老字号",@"体验",@"商城"];
    for (int i = 0; i < 3; i++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100*i, 0, 100, 34)];
        btn.tag = 50 + i;
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btn.titleLabel.font = FONT(16);
        if (i == 0) {
            btn.titleLabel.font = FONT_BOLD(24);
        }
        [btn setTitle:arr[i] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(btnTopAction:) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:btn];
    }
}

- (void)backAction {
    [super backAction];
}

- (void)btnTopAction:(UIButton *)sender {
    self.refreshCount = 1;
    if (sender.tag == 52) {
        
    } else {
        for (int i = 0; i < 2; i++) {
            UIButton *button = [self.view viewWithTag:50 + i];
            button.titleLabel.font = FONT(16);
        }
        sender.titleLabel.font = FONT_BOLD(24);
        self.navSelectedIndex = sender.tag - 50;
    }
   
    if ([sender.titleLabel.text isEqualToString:@"商城"]) {
        WKWebViewController *webVC = [[WKWebViewController alloc] initWithURLString:@"http://sum.kdcer.com/souvenir/index.html?LevelId=3"];
        [self.navigationController pushViewController:webVC animated:YES];
    } else if ([sender.titleLabel.text isEqualToString:@"老字号"]) {
        self.tableView.tableHeaderView = self.tabHeaderView;
    } else if ([sender.titleLabel.text isEqualToString:@"体验"]) {
        NSArray *arr = self.dataDic[@"ty_listLZHBanner"];
        NSMutableArray *imageArr = [[NSMutableArray alloc] init];
        for (int i = 0; i < arr.count; i++) {
            [imageArr addObject:arr[i][@"imgPath"]];
        }
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, (SCREEN_WIDTH - 32) * 180/343)];
        [view addSubview:self.sdcycleScrollView];
        self.tableView.tableHeaderView = view;
        self.sdcycleScrollView.imageURLStringsGroup = imageArr;
    }
    [self.tableView reloadData];
}

- (void)removeChild {
    UIViewController *vc = [self.childViewControllers lastObject];
    [vc willMoveToParentViewController:nil];
    [vc removeFromParentViewController];
    [vc.view removeFromSuperview];
}

#pragma mark --UITableView代理

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        if (self.navSelectedIndex == 0) {
            return self.lzh_listLZHStorylArr.count;
        } else {
            return 0;
        }
    } else {
        if (self.navSelectedIndex == 0) {
            self.tableView.mj_footer.hidden = YES;
            return self.tableViewDataArr.count;
        } else {
            //刷新数据处理
            self.tableView.mj_footer.hidden = (self.listNightSHTweetModelArr.count == 0);
            if (self.listNightSHTweetModelArr.count == self.totalCount) {
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            } else {
                [self.tableView.mj_footer endRefreshing];
            }
            return [self.listNightSHTweetModelArr count];
        }
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    if (section == 1) {
        self.lbTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 31)];
        if (self.navSelectedIndex == 0) {
            self.lbTitle.text = @"   老字号活动";
        } else {
            self.lbTitle.text = @"   老字号攻略";
        }
        self.lbTitle.font = FONT_BOLD(22);
        return self.lbTitle;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    }
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    
    if (indexPath.section == 0) {//只有老字号首页  有第一组,    体验只有一组
        /**
         1一张图 2三张图 3视频
         */
        ListNightSHTweetModel *model0 = self.lzh_listLZHStorylArr[indexPath.row];
        if (model0.cssType == 3) {
            MPMoviePlayerVC *vc = [[MPMoviePlayerVC alloc] init];
            vc.videoTitle = model0.title;
            vc.videoPath = DSStringValue(model0.videoPath);
            vc.fromName = DSStringValue(model0.fromName);
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        } else {
            WKWebViewController *webVC = [[WKWebViewController alloc] initWithURLString:[NSString stringWithFormat:@"%@", model0.linkPath]];
            [self.navigationController pushViewController:webVC animated:YES];
        }
    } else {
        if (self.navSelectedIndex == 0) {
            OldActivityModel *model = self.tableViewDataArr[indexPath.row];
            WKWebViewController *webVC = [[WKWebViewController alloc] initWithURLString:[NSString stringWithFormat:@"%@", model.linkPath]];
            [self.navigationController pushViewController:webVC animated:YES];
        } else {
            /**
             1一张图 2三张图 3视频
             */
            ListNightSHTweetModel *model1 = self.listNightSHTweetModelArr[indexPath.row];
            if (model1.cssType == 3) {
                MPMoviePlayerVC *vc = [[MPMoviePlayerVC alloc] init];
                vc.videoTitle = model1.title;
                vc.videoPath = model1.videoPath;
                vc.fromName = model1.fromName;
                vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            } else {
                WKWebViewController *webVC = [[WKWebViewController alloc] initWithURLString:[NSString stringWithFormat:@"%@", model1.linkPath]];
                [self.navigationController pushViewController:webVC animated:YES];
            }
        }
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 
    if (indexPath.section == 0) {
        ListNightSHTweetModel *model0 = self.lzh_listLZHStorylArr[indexPath.row];
        
        switch (model0.cssType) {
            case 1: {
                
            }
                break;
            case 2: {
                
            }
                break;
            case 3: {
                static NSString *CellIdentifier = @"OldTableViewCell";
                OldTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                if (cell == nil) {
                    cell = [[OldTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                }
                cell.videoImage.hidden = NO;
                cell.lbTitle.hidden = cell.lbDetail.hidden = YES;
        
                [cell updateOldTableViewCellVideoWithdata:model0];
                return cell;
            }
                break;
            default: {
                static NSString *CellIdentifier = CellID_DiscoverTableViewCell;
                DiscoverTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                if (cell == nil) {
                    cell = [[DiscoverTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                }
                cell.imageVideo.hidden = YES;
                [cell.shareBtn addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
                cell.shareBtn.tag = indexPath.row + 1000;
                [cell updateDiscoverTableViewCellWithModel:model0];
                return cell;
            }
                break;
        }
        
    } else {
        if (self.navSelectedIndex == 0) {
            OldActivityModel *model2 = self.tableViewDataArr[indexPath.row];
            static NSString *CellIdentifier = @"OldTableViewCell";
            OldTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            if (cell == nil) {
                cell = [[OldTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
            }
            cell.videoImage.hidden = YES;
            cell.lbTitle.hidden = cell.lbDetail.hidden = NO;
            [cell updateOldTableViewCellWithdata:model2];
            return cell;
        } else {
            ListNightSHTweetModel *model = self.listNightSHTweetModelArr[indexPath.row];
            /**
             1一张图 2三张图 3视频
             */
            switch (model.cssType) {
                case 1:{//一张小图
                    static NSString *CellIdentifier = CellID_PublicRightImageCell;
                    PublicRightImageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                    if (cell == nil) {
                        cell = [[PublicRightImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                    }
                    cell.shareBtn.tag = indexPath.row + 1000;
                    [cell.shareBtn addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
                    [cell updatePublicRightImageCellWithModel:model];
                    return cell;
                }
                    break;
                case 2:{//三张小图
                    static NSString *CellIdentifier = CellID_PublicThreeImageCell;
                    PublicThreeImageCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                    if (cell == nil) {
                        cell = [[PublicThreeImageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                    }
                    cell.shareBtn.tag = indexPath.row + 1000;
                    [cell.shareBtn addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
                    [cell updatePublicThreeImageCellWithModel:model];
                    return cell;
                }
                    break;
                case 3:{//视频
                    static NSString *CellIdentifier = CellID_DiscoverTableViewCell;
                    DiscoverTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                    if (cell == nil) {
                        cell = [[DiscoverTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                    }
                    cell.imageVideo.hidden = NO;
                    cell.shareBtn.tag = indexPath.row + 1000;
                    [cell.shareBtn addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
                    [cell updateDiscoverTableViewCellWithModel:model];
                    return cell;
                }
                    break;
                default:{//一张大图
                    static NSString *CellIdentifier = CellID_DiscoverTableViewCell;
                    DiscoverTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                    if (cell == nil) {
                        cell = [[DiscoverTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
                    }
                    cell.imageVideo.hidden = YES;
                    cell.shareBtn.tag = indexPath.row + 1000;
                    [cell.shareBtn addTarget:self action:@selector(shareAction:) forControlEvents:UIControlEventTouchUpInside];
                    [cell updateDiscoverTableViewCellWithModel:model];
                    return cell;
                }
                    break;
            }
        }
    }
    return nil;
}
#pragma mark - 友盟分享
- (void)shareAction:(UIButton *)sender {
    
    if (self.navSelectedIndex == 0) {
        self.shareDataModel = self.lzh_listLZHStorylArr[sender.tag - 1000];
    } else {
        self.shareDataModel = self.listNightSHTweetModelArr[sender.tag - 1000];
    }
    [self shareAlertView];
}

- (void)shareAlertView {
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    //    蒙板
    UIView *view = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    view.tag = 9998;
    view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
    [window addSubview:view];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRemoveShareView:)];
    [view addGestureRecognizer:tap];
    
    
    UIView *whiteView = [[UIView alloc] initWithFrame:CGRectMake(16, SCREEN_HEIGHT - 120 - 28, SCREEN_WIDTH - 32, 120)];
    whiteView.backgroundColor = [UIColor whiteColor];
    whiteView.tag = 9999;
    ViewBorderRadius(whiteView, 10, 0, [UIColor whiteColor]);
    [window addSubview:whiteView];
    
    //间距
    float weight = 65;
    int range = (whiteView.frame.size.width - weight * 4) / 5;
    NSArray *arr = @[@"微信",
                     @"朋友圈",
                     @"QQ"];
    
    for (int i = 0; i < arr.count; i++) {
        UIButton *imageBtn = [[UIButton alloc] initWithFrame:CGRectMake(range + i * (weight + range), 20, weight, weight)];
        [imageBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"分享%d", i]] forState:UIControlStateNormal];
        [imageBtn addTarget:self action:@selector(shareBtnAction:) forControlEvents:UIControlEventTouchUpInside];
        imageBtn.tag = i + 10000;
        [imageBtn setTitle:arr[i] forState:UIControlStateNormal];
        [whiteView addSubview:imageBtn];
        
        UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(range + i * (weight + range), GetViewYH(imageBtn), weight, 17)];
        lb.tag = i + 10010;
        lb.textColor = UIColorFromRGB(0x333333);
        lb.font = FONT(12);
        lb.text = arr[i];
        lb.textAlignment = 1;
        [whiteView addSubview:lb];
    }
    //    if (![QQApiInterface isQQInstalled]) {//没有安装QQ
    //        UIButton *btn = [whiteView viewWithTag:10002];
    //        btn.hidden = YES;
    //
    //        UILabel *lb = [whiteView viewWithTag:10012];
    //        lb.hidden = YES;
    //    }
    //    if (![WXApi isWXAppInstalled]) { //没有安装微信
    //        UIButton *btn0 = [whiteView viewWithTag:10000];
    //        UIButton *btn1 = [whiteView viewWithTag:10001];
    //        btn0.hidden = YES;
    //        btn1.hidden = YES;
    //
    //        UILabel *lb0 = [whiteView viewWithTag:10010];
    //        UILabel *lb1 = [whiteView viewWithTag:10011];
    //        lb0.hidden = YES;
    //        lb1.hidden = YES;
    //    }
}

- (void)shareBtnAction:(UIButton *)sender {
    [self removeShareView];
    NSInteger platformType = 0;
    switch (sender.tag) {
            case 10000: {
                platformType = 1;//微信聊天
            }
            break;
            case 10001: {
                platformType = 2;//微信朋友圈
            }
            break;
            case 10002: {
                platformType = 4;//QQ聊天
            }
            break;
            case 10003: {
                if ([UserManager sharedUserManager].isLogin) {
                    NSString *str = [NSString stringWithFormat:@"%@", self.shareDataModel.id];
                    NSDictionary *par = @{@"userId":DSStringValue([UserManager sharedUserManager].userInfo.uid),
                                          @"tweetId":str
                                          };
                    
                    [PPNetworkHelper POST:URL_addCollect parameters:par success:^(id responseObject) {
                        [SXLoadingView showAlertHUD:responseObject[@"retMsg"] duration:SXLoadingTime];
                    } failure:^(NSError *error) {
                        [SXLoadingView showAlertHUD:SXLoadingErrorStr duration:SXLoadingTime];
                    }];
                } else {
                    LoginAndRegisterVC *vc = [[LoginAndRegisterVC alloc] init];
                    vc.hidesBottomBarWhenPushed = YES;
                    vc.pushType = 1;
                    [self.navigationController pushViewController:vc animated:YES];
                }
                
                return;
            }
            break;
            
        default:
            break;
    }
    //创建分享消息对象
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    //创建网页内容对象
    NSString *thumbURL = [NSString stringWithFormat:@"%@", self.shareDataModel.imgPath[0]];
    UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:[NSString stringWithFormat:@"%@", self.shareDataModel.fromName] descr:[NSString stringWithFormat:@"%@", self.shareDataModel.title] thumImage:thumbURL];
    //设置网页地址
    shareObject.webpageUrl = [NSString stringWithFormat:@"%@", self.shareDataModel.linkPath];
    //分享消息对象设置分享内容对象
    messageObject.shareObject = shareObject;
    //调用分享接口
    [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
        if (error) {
            UMSocialLogInfo(@"************分享失败 %@*********",error);
        } else {
            if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                UMSocialShareResponse *resp = data;
                //分享结果消息
                UMSocialLogInfo(@"响应消息 %@",resp.message);
                //第三方原始返回的数据
                UMSocialLogInfo(@"原始响应数据 %@",resp.originalResponse);
            } else {
                UMSocialLogInfo(@"响应数据 %@",data);
            }
        }
    }];
}

- (void)tapRemoveShareView:(UITapGestureRecognizer *)tap {
    [self removeShareView];
}

- (void)removeShareView {
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    UIView *view0 = [window viewWithTag:9998];
    UIView *view1 = [window viewWithTag:9999];
    
    [view0 removeFromSuperview];
    [view1 removeFromSuperview];
}

/** 点击图片回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
    NSDictionary *dic = self.dataDic[@"ty_listLZHBanner"][index];
    NSInteger type = [dic[@"type"] integerValue];
    switch (type) {
        case 0:{
            
        }
            break;
        case 1:{//图
            
        }
            break;
        case 2:{//推文
            WKWebViewController *webVC = [[WKWebViewController alloc] initWithURLString:self.dataDic[@"ty_listLZHBanner"][index][@"linkPath"]];
            [self.navigationController pushViewController:webVC animated:YES];
        }
            break;
        case 3:{//小程序
            if ([WXApi isWXAppInstalled]) {
                WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
                launchMiniProgramReq.userName = [NSString stringWithFormat:@"%@", dic[@"appId"]];  //拉起的小程序的username-原始ID
                launchMiniProgramReq.path = [NSString stringWithFormat:@"%@", dic[@"appPath"]];    //拉起小程序页面的可带参路径，不填默认拉起小程序首页
                launchMiniProgramReq.miniProgramType = WXMiniProgramTypeRelease; //拉起小程序的类型
                [WXApi sendReq:launchMiniProgramReq completion:^(BOOL success) {
                    
                }];
            } else {
                [SXLoadingView showAlertHUD:@"您还未安装微信~请先下载安装哦" duration:SXLoadingTime];
            }
        }
            break;
        case 4:{//视频
            
        }
            break;
            
        default:
            break;
    }
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, kNavBarAndStatusBarHeight + 20, SCREEN_WIDTH, SCREEN_HEIGHT - kNavBarAndStatusBarHeight - 20) style:UITableViewStyleGrouped];
        _tableView.delegate = self;
        _tableView.dataSource  = self;
        _tableView.tableHeaderView = self.tabHeaderView;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [_tableView registerNib:[UINib nibWithNibName:@"OldTableViewCell" bundle:nil] forCellReuseIdentifier:@"OldTableViewCell"];
        [_tableView registerNib:[UINib nibWithNibName:@"DiscoverTableViewCell" bundle:nil] forCellReuseIdentifier:CellID_DiscoverTableViewCell];
        [_tableView registerNib:[UINib nibWithNibName:@"PublicRightImageCell" bundle:nil] forCellReuseIdentifier:CellID_PublicRightImageCell];
        [_tableView registerNib:[UINib nibWithNibName:@"PublicThreeImageCell" bundle:nil] forCellReuseIdentifier:CellID_PublicThreeImageCell];
    }
    return _tableView;
}

- (NSMutableArray *)tableViewDataArr {
    if (!_tableViewDataArr) {
        _tableViewDataArr = [[NSMutableArray alloc] init];
    }
    return _tableViewDataArr;
}

- (SDCycleScrollView *)sdcycleScrollView {
    if (!_sdcycleScrollView) {
        _sdcycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(16, 0, SCREEN_WIDTH - 32, (SCREEN_WIDTH - 32) * 180/343) shouldInfiniteLoop:YES imageNamesGroup:nil];
        _sdcycleScrollView.layer.cornerRadius = 10;
        _sdcycleScrollView.layer.masksToBounds = YES;
        _sdcycleScrollView.delegate = self;
        _sdcycleScrollView.showPageControl = YES;
    }
    return _sdcycleScrollView;
}

- (NSDictionary *)dataDic {
    if (!_dataDic) {
        _dataDic = [[NSDictionary alloc] init];
    }
    return _dataDic;
}

- (NSMutableArray *)listNightSHTweetModelArr {
    if (!_listNightSHTweetModelArr) {
        _listNightSHTweetModelArr = [[NSMutableArray alloc] init];
    }
    return _listNightSHTweetModelArr;
}

- (NSMutableArray *)lzh_listLZHStorylArr {
    if (!_lzh_listLZHStorylArr) {
        _lzh_listLZHStorylArr = [[NSMutableArray alloc] init];
    }
    return _lzh_listLZHStorylArr;
}

@end
